// 防抖
function fn1 (fn, time) {
  let _time = null
  return function () {
    const _arg = arguments
    const _this = this
    if (_time) {
      clearTimeout(_time)
    }
    _time = setTimeout(() => {
      fn.apply(_this, _arg)
    }, time)
  }
}

// 节流
function fn2 (fn, time) {
  let isLoading = false
  return function () {
    const _arg = arguments
    if (!isLoading) {
      isLoading = true
      const _this = this
      setTimeout(() => {
        fn.apply(_this, _arg)
        isLoading = false
      }, time)
    }
  }
}
export { fn1, fn2 }
